#include <stdint.h>

#ifndef __ROM_PACKET_H
#define __ROM_PACKET_H


// All binary data in packets is little endian
// The minimum packet size according to the source code seems to be 0x0C (size of the packet header)
// The minimum packet size actually being received is 0x10
//
// To read decrypted packets place a breakpoint or hook on 0x006D7A5, it's the return instruction of the
// individual packet handler routine. The buffer pointer is on the stack at [ESP + 0x0C], 
// packet size is at [ESP + 0x08]

// Packet header
struct RomPacketHeader
{
    uint32_t    size;           // Packet size in bytes
    uint8_t     keybytes[4];    // These bytes are used to decrypt the packet
    uint32_t    counter;        // This appears to increase by 1 every packet you receive, some packets have this set to 0
} __attribute__((packed));


struct RomDecryptionState
{
    /* 0x0000 */    uint8_t     unknown_0[0x14];    
    /* 0x0014 */    uint32_t    not_sure;          // Not sure but its used as argument for a funciton, seems to be always 0
    /* 0x0018 *     uint8_t     unknown_1[0x168];
     */* 0x0180 */    uint8_t     counterA;          // pointer to one of the 10 key bytes
    /* 0x0181 */    uint8_t     counterB;
    /* 0x0182 */    uint8_t     keys[10];          // 10 key bytes
};



#endif
